<?php

date_default_timezone_set('Europe/Copenhagen');

$Actions = array();

function AddAction($NewAction)
{
    echo 'Adding: '.$NewAction->Name().'<br />';

    global $Actions;

    $Actions[count($Actions)] = $NewAction;
}

function RunAction($Action, $Arguments)
{
    global $Actions;

    $Num = count($Actions);
    $Found = false;

    for ( $I = 0; $I < $Num; $I++ )
    {
	if ( strcasecmp($Actions[$I]->Name(), $Action ) == 0 )
	{
	    $Found = true;
	    $Actions[$I]->RunAction($Arguments);
	}
    }

    return $Found;
}

class md_MaxsiActionModel
{
    public $mdc_Prepend;
    
    public function Name()
    {
        return 'Action';
    }
    
    public function RunAction($Arguments)
    {
	return false;
    }

    public function SendResponseVariable($Variable, $Data)
    {

	return true;
    }
}

class md_SetAchievementProgress extends md_MaxsiActionModel
{
    public function Name()
    {
	return 'SetAchievementProgress';
    }

    public function SetAchievement($Username, $Achievement, $Progress)
    {
	return true;
    }

    public function RunAction($Arguments)
    {
	if (!isset($Arguments['Username'])
	|| !isset($Arguments['Achievement'])
	|| !isset($Arguments['Progress'])) { return false; }

	return SetAchievement($Arguments['Username'],$Arguments['Achievement'],$Arguments['Progress']);
    }
}

AddAction(new md_SetAchievementProgress);

class md_GetAchievementProgress extends md_MaxsiActionModel
{
    public function Name()
    {
	return 'GetAchievementProgress';
    }

    public function GetAchievement($Username, $Achievement)
    {
	$Progress   =	'1';

	SendResponseVariable('Achievement', $Achievement);
	SendResponseVariable('AchievementProgress', $Progress);

	return true;
    }

    public function RunAction($Arguments)
    {
	if (!isset($Arguments['Username'])
	|| !isset($Arguments['Achievement'])) { return false; }

	return GetAchievement($Arguments['Username'],$Arguments['Achievement']);
    }
}

AddAction(new md_GetAchievementProgress);

class md_DoSomethingSilly extends md_MaxsiActionModel
{
    public function Name()
    {
	return 'DoSomethingSilly';
    }

    public function RunAction($Arguments)
    {
	echo 'Aha!';
    }
}

AddAction(new md_DoSomethingSilly);

RunAction('DoSomethingSilly',array());

?>
